﻿using System;

namespace VsTortoiseSVN
{
    public static class Globals
    {
        /// <summary>
        /// Specifies the VsTortoise build number.
        /// </summary>
        public const int Build = 33;

        /// <summary>
        /// Specifies whether VsTortoise is a beta version.
        /// </summary>
        public const bool Beta = true;

        /// <summary>
        /// Specifies whether VsTortoise is an alpha version.
        /// </summary>
        public const bool Alpha = false;

        /// <summary>
        /// Gets a string containing the VsTortoise version and beta information.
        /// </summary>
        public static string VersionString
        {
            get
            {
                return string.Format("{0}{1}", Build, Beta ? " Beta": Alpha ? " Alpha" : "");
            }
        }

        /// <summary>
        /// Gets the full application title.
        /// </summary>
        public static string AppTitle
        {
            get
            {
#if SVN18
                return string.Format("VsTortoise {0} for SVN 1.8", VersionString);
#elif SVN17
                return string.Format("VsTortoise {0} for SVN 1.7", VersionString);
#else
                return string.Format("VsTortoise {0}", VersionString);
#endif
            }
        }

        /// <summary>
        /// Gets/sets the DTE instance of the current Visual Studio Process.
        /// This must be one of the very first tasks performed during addin initialization.
        /// </summary>
        public static EnvDTE80.DTE2 DTE { get; set; }

        /// <summary>
        /// Gets the Visual Studio version.
        /// VS 2005 = 8.0
        /// VS 2008 = 9.0
        /// VS 2010 = 10.0
        /// VS 2012 = 11.0
        /// VS 2013 = 12.0
        /// </summary>
        public static float VSVersion
        {
            get
            {
                float version;

                if (float.TryParse(DTE.Version, System.Globalization.NumberStyles.Float, System.Threading.Thread.CurrentThread.CurrentUICulture, out version))
                    return version;

                if (float.TryParse(DTE.Version, System.Globalization.NumberStyles.Float, System.Threading.Thread.CurrentThread.CurrentCulture, out version))
                    return version;

                if (float.TryParse(DTE.Version, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), out version))
                    return version;

                return -1;
            }
        }

        /// <summary>
        /// Gets whether the running Visual Studio instance is 2010 or newer.
        /// </summary>
        public static bool IsVS2010OrNewer
        {
            get
            {
                return VSVersion >= 10;
            }
        }

        private static void CheckStaticAssertions()
        {
            // generate compile error when I broke alpha/beta flags
            byte wrongAlphaBetaFlags = Alpha && Beta ? -1 : 0;
        }
    }
}
